package com.xyh.springaidemo1.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;


@RestController
@RequestMapping("/api/v1")
public class aiStart {
    private final ChatClient chatClient;

    public aiStart(ChatClient aiClient) {
        this.chatClient = aiClient;
    }

    @GetMapping("/chat")
    public Flux<String> chat(
            @RequestParam(value = "message", defaultValue = "Hi") String message
    ) {
        Flux<String> content = chatClient.prompt().user(message).stream().content();
        return content;
    }
}
